package com.zhuiyun.educations.api.sysroleback.controller;

import com.zhuiyun.educations.api.sysroleback.entiy.SysRoleBack;
import com.zhuiyun.educations.api.sysroleback.service.SysRoleBackService;
import com.zhuiyun.educations.common.response.CommonResult;
import com.zhuiyun.educations.util.pageUtil.PageRequest;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @ClassName SysRoleBackController
 * @Description TODO
 * @Author MJL
 * @Date 2023/6/15 20:42
 **/
@RestController
@RequestMapping("/Role")
public class SysRoleBackController {
    @Resource
    SysRoleBackService sysRoleBackService;
    /**
    * @Author MJL
    * @Description todo 角色表全查
    * @Date 2023/6/15 20:53
    * @Return  * @param null
    */
    @GetMapping("/SysRoleList")
    public CommonResult SysRoleList(SysRoleBack sysRoleBack, PageRequest pageRequest){
        return CommonResult.ok(sysRoleBackService.SysRoleList(sysRoleBack,pageRequest));
    }
    /**
    * @Author MJL
    * @Description todo 角色表添加
    * @Date 2023/6/16 14:18
    * @Return  * @param null
    */
    @PostMapping("SysRoleAdd")
    public CommonResult SysRoleAdd(@RequestBody SysRoleBack sysRoleBack){
        int i = sysRoleBackService.SysRoleAdd(sysRoleBack);
        if (i>0){
            return CommonResult.ok("恭喜您，添加成功");
        }else
            return CommonResult.error("很抱歉，添加失败");
    }
    /**
    * @Author MJL
    * @Description todo 角色表删除
    * @Date 2023/6/21 15:47
    * @Return  * @param null
    */
    @DeleteMapping("/SysRoleUpdateDelete")
    public CommonResult SysRoleUpdateDelete(Integer id){
        int i = sysRoleBackService.SysRoleUpdateDelete(id);
        if (i>0){
            return CommonResult.ok("删除成功");
        } else {
            return CommonResult.error("删除失败");
        }
    }
    /**
    * @Author MJL
    * @Description todo 角色表修改
    * @Date 2023/6/21 15:53
    * @Return  * @param null
    */
    @PutMapping("/SysRoleUpdate")
    public CommonResult SysRoleUpdate(@RequestBody SysRoleBack sysRoleBack){
        int i = sysRoleBackService.SysRoleUpdate(sysRoleBack);
        if (i>0){
            return CommonResult.ok("修改成功");
        }else {
            return CommonResult.error("修改失败");
        }
    }
    /**
    * @Author MJL
    * @Description todo 分配权限
    * @Date 2023/6/23 14:38
    * @Return  * @param null
    */
    @PostMapping("/SysRoleAssignment")
    public CommonResult SysRoleAssignment(@RequestBody SysRoleBack sysRoleBack){
        System.out.println(sysRoleBack);
        int i = sysRoleBackService.SysRoleAssignment(sysRoleBack);
        if (i>0){
            return CommonResult.ok("权限分配成功");
        }else {
            return CommonResult.error("权限分配失败，请联系管理员");
        }
    }


}
